$NG.AllReady(function (page, { useAction, useBeforeClick, useValuesChange, useClick, useUpdateRow, subscribe, useUpdateRows }) {
    const mstform = $NG.getCmpApi("p_form_aqfysytjtz_m")
    const dgrid1 = $NG.getCmpApi("")
    const getHeadValue = (str)=>mstform.getItem(str).getValue()

    useValuesChange(()=>{
        getAqAmt()
    },"p_form_aqfysytjtz_m.u_aqfyysjhsysj")

    
    useValuesChange(()=>{
        selectProjectTypeRete()
    },"p_form_aqfysytjtz_m.u_xmlx")

    useValuesChange(()=>{
        const u_xmyqtrbl = mstform.getItem("u_xmyqtrbl").getValue()
        const u_flfgyqtrbl = mstform.getItem("u_flfgyqtrbl").getValue()

        if((Number(u_xmyqtrbl) || 0) < (Number(u_flfgyqtrbl) || 0)){
            $NG.alert("项目要求投入比例不允许低于法律法规！")
            mstform.getItem("u_xmyqtrbl").setValue(u_flfgyqtrbl)
        }
    },"p_form_aqfysytjtz_m.u_xmyqtrbl")

    // 根据项目类型找比例
    async function getAqAmt(){
        const phid = getHeadValue("u_aqfyysjhsysj")
        if(!phid) return
        const res = await $NG.execServer("SELECT",{sql:`select u_aqfyysjije from p_form_aqfyysjh_m where phid = '${phid}'`})
        if(res.count == 0) return 
        const datas = JSON.parse(res.data)[0].extendObjects
        mstform.getItem("u_aqfyysjhje").setValue(datas.u_aqfyysjije)
    }
    
    // 根据项目类型找比例
    async function selectProjectTypeRete(){
        const phid = mstform.getItem("u_xmlx").getText()
        if(!phid) return
        const res = await $NG.execServer('SELECT',{sql:`select c_name,c_descript from fg_simple_data where c_type = 'aqgl_flfgyqtrbl'  and (cancel_flg is null or cancel_flg=0)`})
        if(res.count == 0) return 
        const datas = JSON.parse(res.data)
        datas.forEach(el=>{
            const item = el.extendObjects
            console.log(`phid`,item.c_descript.includes(phid),phid);
            if(item.c_descript.includes(phid)){
                mstform.getItem("u_flfgyqtrbl").setValue((Number(item.c_name) || 0))
            }
        })
    }
})